<template>
	<view class="status-bar">

	</view>
	<uni-nav-bar left-icon="left" @clickLeft="leftback" :title="title" :border="false" :height="barhig"
		class="header-title" />
	<view class="container" :style="`padding-top:${systemBarHeight+64}px`">
		<reservationTable :tableData="tableData"></reservationTable>
		<view class="affrim">
			<text>挂号前仔细阅读</text><text class="deal" @click="xuzhi">《挂号须知》</text>
			<button type="primary" @click="amendyuyue">确认预约</button>
		</view>
	</view>
</template>

<script>
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import storage from '@/utils/storage.js'
	import formatDay from "@/utils/format.js"
	import {
		addhzjuy
	} from '@/utils/axios.js'
	import reservationTable from '@/components/bookingReg/reservationTable/reservationTable.vue'
	import {
		ref,
		reactive,
		toRefs,
		onMounted
	} from 'vue'
	export default {
		components: {
			reservationTable
		},
		setup() {

			const title = ref('确定预约信息')
			const data = reactive({
				barhig: '120rpx',
				systemBarHeight: null,
				tableData: {

				},
				fromdata: {}

			})

			onLoad(option => {
				data.tableData = JSON.parse(option.item)
				console.log(data.tableData);

				let user = JSON.parse(storage.get('hzdata'))
				data.fromdata.patients_id = user.patients_id
				data.fromdata.doctor_id = data.tableData.yisen.doctor_id
				data.fromdata.rt_status = 0
				data.fromdata.startDate = formatDay(new Date())
				data.fromdata.startTime = data.tableData.sjduan 
				data.fromdata.creadteDate = data.tableData.yonghu.sched_date
				data.fromdata.reser_type = data.tableData.yisen.doctor_job
				data.fromdata.endDate = formatDay(data.tableData.yisen.sched_date)
				data.fromdata.id=data.tableData.yisen.dt_id
				if(data.tableData.sxwu=="上午"){
					data.fromdata.num=parseInt(data.tableData.yisen.am_sy)+1
				}else{
					data.fromdata.num=parseInt(data.tableData.yisen.pm_sy)+1
				}
				data.fromdata.sxw=data.tableData.sxwu
			
			})
			// #ifdef MP-WEIXIN
			const getCapsule = () => {
				// 获取胶囊位置并改变顶部自定义导航栏的位置
				let menuButtonInfo = uni.getMenuButtonBoundingClientRect();

				//让自定义导航栏头部组件始终和胶囊对齐 做到兼容各手机型号
				data.barhig = (menuButtonInfo.top + menuButtonInfo.height) * 2 + 'rpx';
			}
			getCapsule()
			const getSysteminfo = () => {
				uni.getSystemInfo({
					success: res => {
						data.systemBarHeight = res.statusBarHeight;

					}
				});
			}
			getSysteminfo()
			// #endif

			const amendyuyue = () => {
				storage.set('tableData',data.tableData)
				console.log(data.fromdata);
                addhzjuy(data.fromdata).then(res=>{
					console.log(res);
				})
				uni.navigateTo({
					url: "/pages/home/bookingReg/subscribeWin/subscribeWin"
				})
			}
			const xuzhi = () => {
				uni.navigateTo({
					url: "/pages/home/bookingReg/information/information"
				})
			}
			const leftback = () => {
				storage.remove('hzdata')
				uni.switchTab({
					url: '/pages/home/index/index'
				});
			}
			return {
				title,
				...toRefs(data),
				amendyuyue,
				xuzhi,
				leftback
			}
		}
	}
</script>

<style lang="scss">
	.status-bar {
		height: var(--status-bar-height);
		width: 100%;
		background-color: #fff;
		position: fixed;
		top: 0;
		z-index: 998999;
	}

	.header-title {
		position: fixed;
		width: 100%;
		top: var(--status-bar-height);
		z-index: 998999;
	}

	.container {
		box-sizing: border-box;
		padding: 0 36rpx;

		.affrim {
			padding: 36rpx 0 60rpx;

			text {
				font-size: 28rpx;
				color: #ccc;
			}

			.deal {
				color: #0066ff;
			}

			button {
				margin-top: 32rpx;
				background-color: #0066ff;
			}
		}
	}
</style>
